1
従来のコードから生成型AIアプリケーションへ
AI011Lesson 3
00:00

従来のコードから生成型AIアプリケーションへ

ソフトウェア開発の世界は根本的な変化を迎えています。私たちは、厳密なコマンド駆動型のプログラミングから、柔軟で自然言語駆動型の 生成型AI インタラクションへと移行しています。

1. コマンドチェーンの解体

これは何なのか: 従来のアプリケーションは固定されたグラフィカルユーザーインターフェース(GUI)や特定の言語依存のコマンドセットに頼っています。ユーザーが期待される入力から逸脱すると、システムは失敗します。

なぜ重要なのか: 生成型AIアプリケーションは前例のない柔軟性を提供します。ユーザーは自然言語を使って複雑な目標を達成できるようになり、構文ではなく意図に応じて適応するようになります。

2. 非決定性の原則

これは何なのか: 従来のコードでは、$1 + 1$ は常に $2$ に等しくなります。これは決定論的です。 大規模言語モデル(LLMs)一方、逆に確率に基づいて動作します。

どのように動作するのか: 同じプロンプトに対して異なる結果を出力できます。この多様性は特定のパラメータによって管理され、特に 温度が最も注目されます。

3. 基本構成要素:トークンと温度

  • トークン: モデルが使用するテキストの基本的な数値「ブロック」です。単語はこれらのサブワード単位に分解されます。
  • 温度: ランダム性を制御する設定($0.0$ から $1.0$ の範囲)。低値は予測可能で焦点の当たったテキストを生成し、高値は創造的で多様な出力を促進します。
セキュリティ最優先
アプリケーションコードに直接APIキーをハードコーディングしないでください。常に環境変数(例: .env ファイルなど)を使用して、あなたのAIリソースを不正アクセスから保護してください。
app.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why are Large Language Models (LLMs) described as "non-deterministic"?
Because they can produce different results for the same prompt every time.
Because they always return the exact same output for a given input.
Because they cannot run on standard computer processors.
Because they require quantum computing to function.
Question 2
Which parameter should you decrease if you want the AI output to be more predictable and less creative?
Max Tokens
Top-P
Temperature
Frequency Penalty
Challenge: Building a "Study Buddy"
Apply your knowledge to a real-world scenario.
You are building a "Study Buddy" application that must provide strictly factual definitions for students preparing for exams. The application will connect to an Azure OpenAI resource.
Task 1
Identify the optimal Temperature setting for this specific task.
Solution:
Set Temperature to 0.0 or 0.1. This minimizes randomness and ensures the model provides the most likely, factual, and consistent definitions rather than creative or hallucinated responses.
Task 2
How should you secure the application's sensitive connection data?
Solution:
Move the API_KEY from the main code file into an environment variable or a hidden .env file. Use os.getenv("AZURE_OPENAI_KEY") to retrieve it securely at runtime.